﻿using System;
using System.Windows;
using System.Windows.Data;

namespace Utils.Wpf.Converters
{
	public class NegatedEnumToBooleanConverter : IValueConverter
	{
		#region IValueConverter Members

		public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			string parameterString = parameter as string;

			if (parameterString == null)
			{
				return DependencyProperty.UnsetValue;
			}
			else if (!Enum.IsDefined(value.GetType(), value))
			{
				return DependencyProperty.UnsetValue;
			}
			else
			{
				object parameterValue = Enum.Parse(value.GetType(), parameterString);
				return !parameterValue.Equals(value);
			}
		}

		public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			throw new NotImplementedException();
		}

		#endregion
	}
}